/*
 * main.cc
 *
 *  Created on: Nov 23, 2010
 *      Author: fify
 */

#include <stdio.h>
#include <string.h>

using namespace std;

const int MAX = 2000;

int matrix[MAX][MAX];

int lowbit(int n)
{
	return n & (n ^ (n - 1));
}

void add(int x, int y, int delta)
{
	int i = x;
	while(i < MAX)
	{
		int j = y;
		while(j < MAX)
		{
			matrix[i][j] += delta;
			j += lowbit(j);
		}
		i += lowbit(i);
	}
}

int sum(int x, int y)
{
	int i = x, j = y;
	int ret = 0;
	while(i)
	{
		j = y;
		while(j)
		{
			ret += matrix[i][j];
			j -= lowbit(j);
		}
		i -= lowbit(i);
	}

	return ret;
}

int getSum(int l, int b, int r, int t)
{
	return sum(r, t) - sum(r, b - 1) - sum(l - 1, t) + sum(l - 1, b - 1);
}

int main()
{
	int cmd, s, x, y, a, l, b, r, t;
	for(;;)
	{
		scanf("%d", &cmd);

		switch(cmd)
		{
		case 0:
			scanf("%d", &s);
			memset(matrix, 0, sizeof(matrix));
			break;
		case 1:
			scanf("%d%d%d", &x, &y, &a);
			++x, ++y;
			add(x, y, a);
			break;
		case 2:
			scanf("%d%d%d%d", &l, &b, &r, &t);
			++l, ++b, ++r, ++t;
			printf("%d\n", getSum(l, b, r, t));
			break;
		case 3:
			return 0;
		}
	}
}
